<?php 
$cs=Yii::app()->clientScript;
$cs->registerScript('user_form',<<<END
$(".sel_all").click(function(){\$(this).parent().next("div[id=leftaa]").next("div[id=rightaa]").andSelf().find("input[type=checkbox]").attr('checked',1);});
$(".sel_empty").click(function(){\$(this).parent().next("div[id=leftaa]").next("div[id=rightaa]").andSelf().find("input[type=checkbox]").attr('checked',0);});
$(".lab").click(function(){\$(this).prev("input[type=checkbox]").click();return false;});
$("#sel_all").click(function(){\$("input[type=checkbox]").attr('checked',1);});
$("#sel_empty").click(function(){\$("input[type=checkbox]").attr('checked',0);});
END
);
?>
<div class="yiiForm">
<?php
	echo EHtml::form();	
	EHtml::setOptions(array('errorElement'=> 'span'));
	EHtml::setScenario($update ? 'update' : 'create');				  		
?>
<div>注：<span class="required">*</span>为必填项</div>
<div id="leftaa"  style="border-bottom:0px;">
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'username'); ?>
<?php
if($update){
	echo CHtml::encode($model->username);
	echo CHtml::activeHiddenField($model,'username');
}
else
	echo EHtml::activeTextField($model,'username',array('size'=>16,'maxlength'=>16)); 
?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'password'); ?>
<?php echo EHtml::activePasswordField($model,'password',array('size'=>16,'maxlength'=>16)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'repassword'); ?>
<?php echo EHtml::activePasswordField($model,'repassword',array('size'=>16,'maxlength'=>16)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'true_name'); ?>
<?php echo EHtml::activeTextField($model,'true_name',array('size'=>8,'maxlength'=>8)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'sex'); ?>
男<?php echo CHtml::activeRadioButton($model,'sex',array('value'=>0,'checked'=>'checked'));?>
女<?php echo CHtml::activeRadioButton($model,'sex',array('value'=>1));?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'company'); ?>
<?php echo EHtml::activeTextField($model,'company',array('size'=>16,'maxlength'=>80)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'department'); ?>
<?php echo EHtml::activeTextField($model,'department',array('size'=>16,'maxlength'=>80)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'position'); ?>
<?php echo EHtml::activeTextField($model,'position',array('size'=>16,'maxlength'=>20)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'office'); ?>
<?php echo EHtml::activeTextField($model,'office',array('size'=>16,'maxlength'=>80)); ?>
</div>
<div class="simple1" style="_border-bottom:0;">
<?php echo CHtml::activeLabelEx($model,'duty'); ?>
<?php echo EHtml::activeTextField($model,'duty',array('size'=>16,'maxlength'=>200)); ?>
</div>
</div>
  <div id="rightaa"  style="border-bottom:0px;">
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'entry_time'); ?>
<?php echo EHtml::activeTextField($model,'entry_time',array('size'=>8,'maxlength'=>10,"id"=>"entry_time",)); ?>
<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'entry_time','ifFormat'=>'%Y-%m-%d',));?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'home_addr'); ?>
<?php echo EHtml::activeTextField($model,'home_addr',array('size'=>25,'maxlength'=>80)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'mobile_no'); ?>
<?php echo EHtml::activeTextField($model,'mobile_no',array('size'=>12,'maxlength'=>12)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'birthday'); ?>
<?php echo EHtml::activeTextField($model,'birthday',array('size'=>8,'maxlength'=>10,"id"=>"birthday",)); ?>
<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'birthday','ifFormat'=>'%Y-%m-%d',));?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'educational_background'); ?>
<?php echo EHtml::activeTextField($model,'educational_background',array('size'=>10,'maxlength'=>10)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'household_register'); ?>
<?php echo EHtml::activeTextField($model,'household_register',array('size'=>16,'maxlength'=>80)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'card_id'); ?>
<?php echo EHtml::activeTextField($model,'card_id',array('size'=>18,'maxlength'=>18)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'home_tel'); ?>
<?php echo EHtml::activeTextField($model,'home_tel',array('size'=>16,'maxlength'=>16)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'region'); ?>
<?php echo EHtml::activeTextField($model,'region',array('size'=>16,'maxlength'=>50)); ?>
</div>
<div class="simple1"  style="_border-bottom:0;">
</div>
</div>
<div style="text-align:center;margin-left:0;border:1px solid #90b3bc;border-bottom:0;line-height:40px;"><strong>权限信息:</strong><input type='button' value='全选' id='sel_all'/><input type='button' value='全否' id='sel_empty'/></div>
<?php
$auths=Yii::app()->params['auth'];
$default_operation=Yii::app()->params['auth_operation'];
$contr_sum=count($auths);
$nn=0;
if($contr_sum>0){
	foreach($auths as $indx=>$sval){
		echo "<div style='margin-left:0px;border-bottom:0;border-top:0;padding-left:20px;border:1px solid #90b3bc;line-height:30px;'>$indx<input type='button' value='全选' class='sel_all'/><input type='button' value='全否' class='sel_empty'/></div>";
		$sn=0;$mn=0;
		echo '<div id="leftaa" style="border-top:0;_border-bottom:0;">';
		foreach($sval as $n=>$val){
			$sn++;
			if($sn%2==0) continue;
			echo "<div class='simple".($mn++%2==0?'':1)."'>".CHtml::label($val['name'],false);
			if(isset($val['default_operation'])&&$val['default_operation']==true)
				$operation=$default_operation;
			else
				$operation=$val['operation'];
			foreach($operation as $i=>$v){
				if(isset($v['show'])&&$v['show']==false) continue;//不显示跳过
				$nn++;
				$options=array('name'=>'Users[auth][]','value'=>$val['code'].$i,'id'=>'Users_auth_'.$nn);
				if(!$update||is_array($model->auth)&&in_array($val['code'].$i,$model->auth)) $options+=array('checked'=>true);
				echo CHtml::activeCheckBox($model,'auth',$options);
				//echo CHtml::label($v[0],'Users_auth_'.$nn);
				echo '<a href="#" class="lab">'.$v[0].'</a>';
			}
			echo '</div>';
		}
		echo '</div>';
	
		echo '<div id="rightaa" style="border-top:0;_border-bottom:0;">';$sn=0;$mn=0;
		foreach($sval as $n=>$val){
			$sn++;
			if($sn%2!=0) continue;
			echo "<div class='simple".($mn++%2==0?'':1)."'>".CHtml::label($val['name'],false);
			if(isset($val['default_operation'])&&$val['default_operation']==true)
				$operation=$default_operation;
			else
				$operation=$val['operation'];
			foreach($operation as $i=>$v){
				if(isset($v['show'])&&$v['show']==false) continue;//不显示跳过
				$nn++;
				$options=array('name'=>'Users[auth][]','value'=>$val['code'].$i,'id'=>'Users_auth_'.$nn);
				if(!$update||is_array($model->auth)&&in_array($val['code'].$i,$model->auth)) $options+=array('checked'=>true);
				echo CHtml::activeCheckBox($model,'auth',$options);
				//echo CHtml::label($v[0],'Users_auth_'.$nn);
				echo '<a href="#" class="lab">'.$v[0].'</a>';
			}
			echo '</div>';
		}
		if($sn%2==1) echo "<div class='simple".($mn%2==0?'':1)."'></div>";
		echo '</div>';
	}
}	
?>

<div class="action">
<?php echo EHtml::submitButton($update ? '更新信息' : '添加信息'); ?>
</div>

<?php echo EHtml::endForm(); ?>

</div><!-- yiiForm -->
<?php 
if($model->hasErrors()) echo "<script>alert('您填写的信息有误！请根据页面红色图标提示修改。');</script>";
?>